function delay(time) {
    return new Promise(resolve => {
        setTimeout(resolve, time)
    })
}

export default {
    namespace: 'counter',
    state: {
        num: 0,
    },
    effects: {
        async asyncAdd(action, { put }) {
            await delay(2000)
            put({ type: 'add' })
        },
    },
    reducers: {
        add(action, state) {
            return { ...state, num: state.num + 1 }
        },
        minus(action, state) {
             return { ...state, num: state.num - 1 }  
        },
    },
}